home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / vat060 / example2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-27  |  2.4 KB  |  67 lines

  1. /**************************************************************************
  2.  
  3.   EXAMPLE2.C
  4.  
  5.   Written by Eric Jorgensen (1995)
  6.  
  7.   The is an example program to illustrate how to use Varmint's Audio
  8.   Tools to play .mid files.
  9.  
  10.  
  11. **************************************************************************/
  12.  
  13. #include "sound.h"
  14. #include <conio.h>
  15.  
  16.  
  17. void main(void)
  18. {
  19.   int i;
  20.                                            // You need a MIDI structure to
  21.                                           // hold the data from the .mid file.
  22.   MIDI far *song;
  23.                                           // You will also need a character
  24.                                           // string to catch any error
  25.                                           // messages from LoadMidi().
  26.   char errstring[100];
  27.                                           // Lastly, you will need an
  28.                                           // instruument definition to set
  29.                                           // up FM voices.
  30.   BYTE inst[11] =
  31.     { 0x03,0x01,0x00,0x00,0xF3,0xE4,0x64,0x35,0x00,0x01,0x00}; // Harpsichord
  32.  
  33.                                            // In general, it is good to perform
  34.                                            // all file access before settup
  35.                                            // up the sound blaster.
  36.   song = LoadMidi("bach.mid",errstring);
  37.   if(!song) {
  38.     printf("ERROR loading midi:  %s\n",errstring);
  39.     exit(1);
  40.   }
  41.                                            // Set up the sound blaster.
  42.   if(!SBSetUp()) {
  43.     printf("SB_Setup returned this error: %s \n",errname[sberr]);
  44.     FreeMidi(song);                       // Free the Midi you just loaded.
  45.     exit(1);
  46.   }
  47.  
  48.   GoVarmint();                            // Start up the sound Kernel.
  49.  
  50.   FMReset();                              // Get the FM chip ready.
  51.  
  52.   for(i = 0; i < 9; i++) {                // Initialize all the voices
  53.     FMSetVolume(i,0);                     // Turn each voice off.
  54.     FMSetVoice(i,inst);                   // Set each voice to a harpsichord.
  55.   }
  56.  
  57.   midi_data = song;                       // Tell VAT which song to play.
  58.   MidiCommand(v_play);                    // Start the music!
  59.  
  60.   printf("Press a key to quit.\n");
  61.   getch();
  62.  
  63.   DropDeadVarmint();                      // Stop the SB interrupt.
  64.   SBCleanUp();                            // Clean up sound stuff.
  65.   FreeMidi(song);                         // Free our sond effect.
  66.  
  67. }